package com.szcatic.ework.utils;

import javax.servlet.http.HttpServletRequest;

import eu.bitwalker.useragentutils.UserAgent;

/**
 * 获得用户客户端信息
 * @author Administrator
 *
 */
public class UserAgentUtils {
	
	public static void main(String[] args) {
		String userAgentStr = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1";
		
		UserAgent userAgent = UserAgent.parseUserAgentString(userAgentStr);
		
		System.out.println(userAgent.getId() + ":" + userAgent.getOperatingSystem()
				+ ":" + userAgent.getBrowser() + ":" + userAgent.getBrowserVersion());
	}
	
	public static UserAgent getUserAgent(HttpServletRequest request) {
		return new UserAgent(request.getHeader("User-Agent"));
	}
	
	/**
	 * 获得浏览器信息
	 * @return
	 */
	public static String getBrowser(HttpServletRequest request) {
		return getUserAgent(request).getBrowser().getName() + ":" + getUserAgent(request).getBrowserVersion().getVersion();
	}
	
	/**
	 * 获得操作系统信息
	 * @param request
	 * @return
	 */
	public static String getOS(HttpServletRequest request) {
		return getUserAgent(request).getOperatingSystem().getName();
	}

}
